// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   SimpleSimObject.java

package jones;

import java.util.ArrayList;
import java.util.List;

// Referenced classes of package jones:
//            SimObject

public abstract class SimpleSimObject
    implements SimObject
{

    private List updateBefore = null;
    private List updateAfter = null;

    public SimpleSimObject()
    {
        updateBefore = ((List) (new ArrayList()));
        updateAfter = ((List) (new ArrayList()));
    }

    public final void update(double time)
    {
        for (int i = 0; i < updateBefore.size(); i++)
            ((SimObject)updateBefore.get(i)).update(time);

        updateThis(time);
        for (int i = 0; i < updateAfter.size(); i++)
            ((SimObject)updateAfter.get(i)).update(time);

    }

    public void updateBefore(SimObject o)
    {
        if (updateBefore.contains(((Object) (o))) || updateAfter.contains(((Object) (o))))
            throw new IllegalArgumentException("Already being updated!");
        updateBefore.add(((Object) (o)));
        if (!verify())
            throw new IllegalStateException("Update sequence is a loop!");
        else
            return;
    }

    public void updateAfter(SimObject o)
    {
        if (updateBefore.contains(((Object) (o))) || updateAfter.contains(((Object) (o))))
            throw new IllegalArgumentException("Object already added!");
        updateAfter.add(((Object) (o)));
        if (!verify())
            throw new IllegalStateException("Update sequence is a loop!");
        else
            return;
    }

    public abstract void updateThis(double d);

    public boolean verify()
    {
        List nodes = ((List) (new ArrayList()));
        List expanded = ((List) (new ArrayList()));
        nodes.add(((Object) (this)));
        while (!nodes.isEmpty()) 
        {
            Object o = nodes.remove(0);
            if (o instanceof SimpleSimObject)
            {
                SimpleSimObject sim = (SimpleSimObject)o;
                if (expanded.contains(((Object) (sim))))
                    return false;
                nodes.addAll(((java.util.Collection) (sim.updateBefore)));
                nodes.addAll(((java.util.Collection) (sim.updateAfter)));
                expanded.add(((Object) (sim)));
            }
        }
        return true;
    }
}
